package com.linkoog.devtools.json.file_editer.editer.ui.jsonTreeTable;

import com.intellij.ui.ColoredTableCellRenderer;
import com.intellij.ui.treeStructure.treetable.TreeTable;
import com.intellij.ui.treeStructure.treetable.TreeTableTree;
import com.linkoog.devtools.json.file_editer.editer.ui.JackJsonTreeNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.tree.TreePath;

public class TableKeyRenderer extends ColoredTableCellRenderer {


    @Override
    protected void customizeCellRenderer(@NotNull JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
        if (table instanceof TreeTable){
            TreeTable treeTable = (TreeTable)table;
            final TreeTableTree tree = treeTable.getTree();
            TreePath pathForRow = tree.getPathForRow(row);
            JackJsonTreeNode node = (JackJsonTreeNode) pathForRow.getLastPathComponent();
            if (node.isArrayItem()) {
                this.append("[" + node.getName() + "]", JsonTreeTableStyles.indexAttribute);
            } else {
                this.append(node.getName(), JsonTreeTableStyles.indexAttribute);
            }
        }
    }
}
